// components/Header/index.js
let that = this;
const app=getApp()
Component({
  /**
   * 组件的属性列表
   */
  options: {
    multipleSlots: true  // 重要，启用组件定义时的多 slot 支持
  },
  properties: {
    titleColor:{
      type: String,
      value:'#fff'
    },
    // 导航栏标题
    title: {
      type: String,
      value: "标题"
    },
   
    // 导航栏背景图
    backgroundImage: {
      type: String,
      value: ""
    },
    navbackgroundColor: {
      type: String,
      value: ""
    },
    // 图片高度
    bgImageHeight: {
      type: String,
      value: ''
    },
    // 控制是否有遮罩层
     ismasking: {
      type: Boolean,
      value: false
    },
    fatherShowBack:{
      type: Boolean,
      value: false
    },
    // 滚动高度
    scrollTop: {
      type: Number,
      value: 0,
      observer: (v) =>  that.resetNavStyle(v)
    }
  },
  /**
   * 组件的初始数据
   */
  data: {
    navBarHeight: 0,
    isFixedBg: false,     // 是否显示背景图,
    isShowBack:false
  },
  ready(){
    that = this;
    this.setData({
      isFixedBg: this.data.backgroundImage||this.data.navbackgroundColor,
    })
    this.initialStatusHeight();
    this.initialBackStatus();
  },
  /**
   * 组件的方法列表
   */
  methods: {
    // 调整导航样式
    resetNavStyle(top){
      this.setData({
        isFixedBg: top<this.data.navBarHeight
      })
    },
    // 初始化状态栏高度
    initialStatusHeight(){
      const sysInfo = wx.getSystemInfoSync();
      this.setData({
        navBarHeight: sysInfo.statusBarHeight,
        bgImageHeight:!this.data.bgImageHeight ?( sysInfo.statusBarHeight+41 +'px')  :this.data.bgImageHeight

      });
    },
    // 初始化返回按钮状态
    initialBackStatus(){
      const pages = getCurrentPages();
      this.setData({
        isShowBack:( pages.length>=2&&pages[pages.length-1].route!='pages/login/index')||this.data.fatherShowBack
      })
    },
    // 返回事件
    backEvent(){
      if(this.data.fatherShowBack){
        wx.switchTab({
          url: '/pages/index/index',
        })
      }else{
        wx.navigateBack();

      }
    }
  },
})